File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change
1
+ const channel = new BroadcastChannel ( 'closeSurveyWidgets' ) ;
2
+
3
+ document . addEventListener ( 'closeSurveyWidgets' , ( event ) => {
4
+ const post_message = {
5
+ url : event . detail . url ,
6
+ message : 'closeSurveyWidgets'
7
+ }
8
+ channel . postMessage ( post_message ) ;
9
+
10
+ } ) ;
11
+
12
+ channel . onmessage = ( event ) => {
13
+ // remove all survey containers from non active tabs if the url matches with active tab
14
+ if ( event . data . message === 'closeSurveyWidgets' ) {
15
+ const elements = document . querySelectorAll ( '.document-vote' ) ;
16
+ const matchAny = Array . from ( elements ) . some ( element => {
17
+ // Extract the KB slug from both URLs
18
+ const elementKbSlug = element . dataset . pageUrl . match ( / k b \/ ( [ ^ / ] + ) / ) ?. [ 1 ] ;
19
+ const eventKbSlug = event . data . url . match ( / k b \/ ( [ ^ / ] + ) / ) ?. [ 1 ] ;
20
+
21
+ return elementKbSlug ?. toLowerCase ( ) === eventKbSlug ?. toLowerCase ( ) ;
22
+ } ) ;
23
+ if ( matchAny ) {
24
+ elements . forEach ( element => element . remove ( ) ) ;
25
+ }
26
+ }
27
+ }
28
+
29
+
1
30
document . addEventListener ( 'alpine:init' , ( ) => {
2
31
Alpine . data ( 'surveyForm' , ( ) => ( {
3
32
selectedReason : '' ,
Original file line number Diff line number Diff line change @@ -352,7 +352,7 @@ <h3 class="{% if close_button %}sumo-card-heading{% else %}sidebar-subheading fo
352
352
{% set header = _('Was this article helpful?') %}
353
353
{% endif %}
354
354
{% if document.allows_vote(request) and not document.current_revision.has_voted(request) %}
355
- < div class ="document-vote elevation-02 text-center ">
355
+ < div class ="document-vote elevation-02 text-center " data-page-url =" {{ request.path }} " >
356
356
< form class ="document-vote--form helpful "
357
357
hx-post ="{{ url('wiki.document_vote', document_slug=document.slug) }} "
358
358
hx-indicator =".wait "
Original file line number Diff line number Diff line change @@ -1360,7 +1360,9 @@ def handle_vote(request, document_slug):
1360
1360
1361
1361
if request .headers .get ("HX-Request" ) and survey_context :
1362
1362
survey_html = render_to_string ("wiki/includes/survey_form.html" , survey_context , request )
1363
- return HttpResponse (survey_html )
1363
+ response = HttpResponse (survey_html )
1364
+ response ["HX-Trigger" ] = json .dumps ({"closeSurveyWidgets" : {"url" : request .path }})
1365
+ return response
1364
1366
return HttpResponseRedirect (revision .document .get_absolute_url ())
1365
1367
1366
1368
You can’t perform that action at this time.
0 commit comments